package smap;

import BD.*;
import ConexaoBackupBD.MetodosVerificacaoBD;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import java.awt.event.KeyEvent;

import DAO.TurmaDisciplinaDAO;
import DAO.TurmaAlunoDisciplinaDAO;
import DAO.CursoDAO;
import DAO.AreaDAO;
import DAO.TurmaDAO;
import DAO.DisciplinaDAO;
import ConexaoBackupBD.Relatorios;
import DAO.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TelaTurmaDisciplina extends javax.swing.JDialog {
    
    TurmaDisciplinaBD tdbd = new TurmaDisciplinaBD();
    TurmaDisciplinaDAO tdbdDao = new TurmaDisciplinaDAO();
    
    TurmaAlunoDisciplinaBD tabd = new TurmaAlunoDisciplinaBD();
    TurmaAlunoDisciplinaDAO tabdDao = new TurmaAlunoDisciplinaDAO();
    
    //carregar combobox area
    AreaDAO areDao = new AreaDAO();
    List<AreaBD> listaarea = new ArrayList<AreaBD>();
    
    //carregar combobox curso
    CursoDAO curDao = new CursoDAO();
    List<CursoBD> listacurso = new ArrayList<CursoBD>();
    
    //carregar combobox turma
    TurmaDAO turDao = new TurmaDAO();
    List<TurmaBD> listaturma = new ArrayList<TurmaBD>();
    
    //carregar combobox professor
    ProfessorDAO proDao = new ProfessorDAO();
    List<ProfessorBD> listaprofessor = new ArrayList<ProfessorBD>();
    
    //carregar combobox disciplina
    DisciplinaDAO disDao = new DisciplinaDAO();
    List<DisciplinaBD> listadisciplina = new ArrayList<DisciplinaBD>();
    
    int flagAno = 0; //para o componente jYearChooser não dar erro
    int flagAnoIngresso = 0;
    
    MateriasConcluidasDAO mcDAO = new MateriasConcluidasDAO();
    AtividadesDAO atDAO = new AtividadesDAO();

    
    public TelaTurmaDisciplina(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    } 
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlAluDis = new javax.swing.JPanel();
        pnlAlunoDisciplina = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblAluDis = new javax.swing.JTable();
        pnlAlunoCurso = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblAluno = new javax.swing.JTable();
        btnAdicionarAluno = new javax.swing.JButton();
        btnRemoverAluno = new javax.swing.JButton();
        lblCurso = new javax.swing.JLabel();
        cmbCurso = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jycAnoIngresso = new com.toedter.calendar.JYearChooser();
        pnlVoltar = new javax.swing.JPanel();
        btnVoltar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        pnlPesquisarTurma = new javax.swing.JPanel();
        jycAno = new com.toedter.calendar.JYearChooser();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cmbTurma = new javax.swing.JComboBox();
        pnlDisciplina = new javax.swing.JPanel();
        lblDisciplina = new javax.swing.JLabel();
        cmbDisciplina = new javax.swing.JComboBox();
        cmbSemestre = new javax.swing.JComboBox();
        cmbProfessor = new javax.swing.JComboBox();
        lblSemestre = new javax.swing.JLabel();
        lblProfessor = new javax.swing.JLabel();
        lblArea = new javax.swing.JLabel();
        cmbArea = new javax.swing.JComboBox();
        btnAssociar = new javax.swing.JButton();
        btnTelaArea = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblTurDis = new javax.swing.JTable();
        btnExcluir = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        btnSalvarNotas = new javax.swing.JButton();
        btnRelatorio = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Administrar Turma");
        setResizable(false);

        pnlAluDis.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.lightGray, null), "Cadastrar aluno na disciplina"));

        pnlAlunoDisciplina.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.lightGray), "Alunos cadastrados na disciplina"));

        tblAluDis.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "RA", "Nome", "Nota", "Freq.", "Aprovado", "Créditos"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Float.class, java.lang.Float.class, java.lang.Boolean.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblAluDis.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblAluDis.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(tblAluDis);
        tblAluDis.getColumnModel().getColumn(0).setPreferredWidth(20);
        tblAluDis.getColumnModel().getColumn(1).setPreferredWidth(250);
        tblAluDis.getColumnModel().getColumn(2).setPreferredWidth(10);
        tblAluDis.getColumnModel().getColumn(3).setPreferredWidth(10);
        tblAluDis.getColumnModel().getColumn(4).setPreferredWidth(45);
        tblAluDis.getColumnModel().getColumn(5).setPreferredWidth(40);

        javax.swing.GroupLayout pnlAlunoDisciplinaLayout = new javax.swing.GroupLayout(pnlAlunoDisciplina);
        pnlAlunoDisciplina.setLayout(pnlAlunoDisciplinaLayout);
        pnlAlunoDisciplinaLayout.setHorizontalGroup(
            pnlAlunoDisciplinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 576, Short.MAX_VALUE)
        );
        pnlAlunoDisciplinaLayout.setVerticalGroup(
            pnlAlunoDisciplinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
        );

        pnlAlunoCurso.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.lightGray), "Alunos cadastrados no curso"));

        tblAluno.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "RA", "Nome"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblAluno.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblAluno.getTableHeader().setReorderingAllowed(false);
        jScrollPane3.setViewportView(tblAluno);
        tblAluno.getColumnModel().getColumn(0).setMinWidth(80);
        tblAluno.getColumnModel().getColumn(0).setPreferredWidth(80);
        tblAluno.getColumnModel().getColumn(0).setMaxWidth(100);

        javax.swing.GroupLayout pnlAlunoCursoLayout = new javax.swing.GroupLayout(pnlAlunoCurso);
        pnlAlunoCurso.setLayout(pnlAlunoCursoLayout);
        pnlAlunoCursoLayout.setHorizontalGroup(
            pnlAlunoCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );
        pnlAlunoCursoLayout.setVerticalGroup(
            pnlAlunoCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
        );

        btnAdicionarAluno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/add-icon.png"))); // NOI18N
        btnAdicionarAluno.setText("Adicionar");
        btnAdicionarAluno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarAlunoActionPerformed(evt);
            }
        });

        btnRemoverAluno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/delete-icon.png"))); // NOI18N
        btnRemoverAluno.setText("Remover");
        btnRemoverAluno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverAlunoActionPerformed(evt);
            }
        });

        lblCurso.setText("Curso:");

        cmbCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbCursoActionPerformed(evt);
            }
        });

        jLabel3.setText("Ingresso:");

        jycAnoIngresso.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jycAnoIngressoPropertyChange(evt);
            }
        });

        javax.swing.GroupLayout pnlAluDisLayout = new javax.swing.GroupLayout(pnlAluDis);
        pnlAluDis.setLayout(pnlAluDisLayout);
        pnlAluDisLayout.setHorizontalGroup(
            pnlAluDisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlAlunoDisciplina, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pnlAlunoCurso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(pnlAluDisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlAluDisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlAluDisLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jycAnoIngresso, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblCurso)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbCurso, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlAluDisLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnAdicionarAluno, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnRemoverAluno, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(114, 114, 114))))
        );
        pnlAluDisLayout.setVerticalGroup(
            pnlAluDisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlAluDisLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlAluDisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlAluDisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblCurso)
                        .addComponent(cmbCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3))
                    .addComponent(jycAnoIngresso, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlAlunoCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlAluDisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdicionarAluno)
                    .addComponent(btnRemoverAluno))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlAlunoDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pnlVoltar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(192, 192, 192)));

        btnVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/voltar-icon.png"))); // NOI18N
        btnVoltar.setText("Voltar");
        btnVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoltarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlVoltarLayout = new javax.swing.GroupLayout(pnlVoltar);
        pnlVoltar.setLayout(pnlVoltarLayout);
        pnlVoltarLayout.setHorizontalGroup(
            pnlVoltarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlVoltarLayout.createSequentialGroup()
                .addContainerGap(586, Short.MAX_VALUE)
                .addComponent(btnVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(495, 495, 495))
        );
        pnlVoltarLayout.setVerticalGroup(
            pnlVoltarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlVoltarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.lightGray, null), "Cadastrar disciplinas na turma"));

        pnlPesquisarTurma.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.lightGray), "Selecionar Turma"));

        jycAno.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jycAnoPropertyChange(evt);
            }
        });

        jLabel1.setText("Ano:");

        jLabel2.setText("Nome da turma:");

        cmbTurma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTurmaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlPesquisarTurmaLayout = new javax.swing.GroupLayout(pnlPesquisarTurma);
        pnlPesquisarTurma.setLayout(pnlPesquisarTurmaLayout);
        pnlPesquisarTurmaLayout.setHorizontalGroup(
            pnlPesquisarTurmaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPesquisarTurmaLayout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jycAno, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbTurma, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnlPesquisarTurmaLayout.setVerticalGroup(
            pnlPesquisarTurmaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPesquisarTurmaLayout.createSequentialGroup()
                .addGroup(pnlPesquisarTurmaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlPesquisarTurmaLayout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jycAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlPesquisarTurmaLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(pnlPesquisarTurmaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(cmbTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPesquisarTurmaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addContainerGap())
        );

        pnlDisciplina.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.lightGray), "Cadastrar disciplina na turma"));

        lblDisciplina.setText("Disciplina:");

        cmbSemestre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));

        lblSemestre.setText("Semestre:");

        lblProfessor.setText("Professor:");

        lblArea.setText("Área:");

        cmbArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAreaActionPerformed(evt);
            }
        });

        btnAssociar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/add-icon.png"))); // NOI18N
        btnAssociar.setText("Associar");
        btnAssociar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAssociarActionPerformed(evt);
            }
        });

        btnTelaArea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/area-icon.png"))); // NOI18N
        btnTelaArea.setToolTipText("Adicionar nova área");
        btnTelaArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTelaAreaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlDisciplinaLayout = new javax.swing.GroupLayout(pnlDisciplina);
        pnlDisciplina.setLayout(pnlDisciplinaLayout);
        pnlDisciplinaLayout.setHorizontalGroup(
            pnlDisciplinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDisciplinaLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(pnlDisciplinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDisciplinaLayout.createSequentialGroup()
                        .addComponent(lblArea)
                        .addGap(12, 12, 12)
                        .addComponent(cmbArea, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnTelaArea)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblDisciplina)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmbDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlDisciplinaLayout.createSequentialGroup()
                        .addComponent(lblSemestre)
                        .addGap(12, 12, 12)
                        .addComponent(cmbSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)
                        .addComponent(lblProfessor)
                        .addGap(6, 6, 6)
                        .addComponent(cmbProfessor, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnAssociar, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        pnlDisciplinaLayout.setVerticalGroup(
            pnlDisciplinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDisciplinaLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(pnlDisciplinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmbArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnTelaArea)
                    .addGroup(pnlDisciplinaLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(lblArea))
                    .addGroup(pnlDisciplinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblDisciplina)
                        .addComponent(cmbDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(pnlDisciplinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDisciplinaLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(lblSemestre))
                    .addGroup(pnlDisciplinaLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(cmbSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlDisciplinaLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(lblProfessor))
                    .addGroup(pnlDisciplinaLayout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(pnlDisciplinaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbProfessor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnAssociar))))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        tblTurDis.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Semestre", "Disciplina", "Professor", "coddis", "codprofessor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblTurDis.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblTurDis.getTableHeader().setReorderingAllowed(false);
        tblTurDis.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblTurDisMouseClicked(evt);
            }
        });
        tblTurDis.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tblTurDisKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tblTurDis);
        tblTurDis.getColumnModel().getColumn(0).setMinWidth(80);
        tblTurDis.getColumnModel().getColumn(0).setPreferredWidth(80);
        tblTurDis.getColumnModel().getColumn(0).setMaxWidth(100);
        tblTurDis.getColumnModel().getColumn(3).setMinWidth(0);
        tblTurDis.getColumnModel().getColumn(3).setPreferredWidth(0);
        tblTurDis.getColumnModel().getColumn(3).setMaxWidth(0);
        tblTurDis.getColumnModel().getColumn(4).setMinWidth(0);
        tblTurDis.getColumnModel().getColumn(4).setPreferredWidth(0);
        tblTurDis.getColumnModel().getColumn(4).setMaxWidth(0);

        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/delete-icon.png"))); // NOI18N
        btnExcluir.setText("Excluir");
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        btnAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/alterar-icon.png"))); // NOI18N
        btnAlterar.setText("Alterar");
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlDisciplina, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pnlPesquisarTurma, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(150, 150, 150))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlPesquisarTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnExcluir)
                    .addComponent(btnAlterar))
                .addGap(6, 6, 6))
        );

        btnSalvarNotas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/save-icon.png"))); // NOI18N
        btnSalvarNotas.setText("Salvar notas");
        btnSalvarNotas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarNotasActionPerformed(evt);
            }
        });

        btnRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/report-icon.png"))); // NOI18N
        btnRelatorio.setText("Relatório");
        btnRelatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRelatorioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlAluDis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(pnlVoltar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnSalvarNotas)
                .addGap(18, 18, 18)
                .addComponent(btnRelatorio, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlAluDis, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSalvarNotas)
                    .addComponent(btnRelatorio))
                .addGap(11, 11, 11)
                .addComponent(pnlVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void cmbTurmaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTurmaActionPerformed
        if(cmbTurma.getSelectedIndex() != -1){ // tratamento de erro se combo estiver vazio
            carregarTabela();
            //carregar os alunos cadastrados para uma disciplina se 
            //esta estiver selecionada
            carregarAlunoDisciplina();
        }
        else{
            //limpar tables
            limparTableDisciplinas();
            limparTableAlunoDisciplina();
        }
    }//GEN-LAST:event_cmbTurmaActionPerformed

    private void jycAnoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jycAnoPropertyChange
        if(flagAno == 0){
            flagAno = 1;
        }else{
            //limpar combobox
            cmbTurma.removeAllItems();
            carregarComboTurma(jycAno.getValue());
        }
    }//GEN-LAST:event_jycAnoPropertyChange

    private void btnAssociarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAssociarActionPerformed
        //verificar os combobox vazios
        if(cmbTurma.getSelectedIndex() == -1 || cmbTurma.getSelectedIndex() == 0 || cmbDisciplina.getSelectedIndex() == -1 || 
                cmbProfessor.getSelectedIndex() == -1 || cmbProfessor.getSelectedIndex() == 0 ){
            JOptionPane.showMessageDialog(null,"Campos turma, disciplina e professor são obrigatórios", 
                    "Campos Obrigatórios", JOptionPane.INFORMATION_MESSAGE);
        }else{
            tdbd.setNomeTurma(cmbTurma.getSelectedItem().toString());
            tdbd.setNomeDisciplina(cmbDisciplina.getSelectedItem().toString());
            tdbd.setSemestre(Integer.parseInt(cmbSemestre.getSelectedItem().toString()));
            tdbd.setNomeProfessor(cmbProfessor.getSelectedItem().toString());
            
            tdbd.setCodDisciplina(listadisciplina.get(cmbDisciplina.getSelectedIndex()).getCodigo());
            tdbd.setCodProfessor(listaprofessor.get(cmbProfessor.getSelectedIndex()).getCodigo()); 
            
            if(tdbdDao.inserirAssociacao(tdbd)){
                carregarTabela();
            }
            //limpar a relação alunodisciplina pois tblTurDis perde seleção.
            limparTableAlunoDisciplina();
        }
    }//GEN-LAST:event_btnAssociarActionPerformed

    private void btnVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoltarActionPerformed
        this.dispose(); // Fecha Tela Curso
    }//GEN-LAST:event_btnVoltarActionPerformed

    private void cmbCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbCursoActionPerformed
        if(cmbCurso.getSelectedIndex() != -1){ // tratamento de erro se combo estiver vazio
            carregarAluno();
        }
        else{
            DefaultTableModel tbm = (DefaultTableModel)tblAluno.getModel();         

            //Remove as linhas da Jtable, para limpar.
            for(int i = tbm.getRowCount()-1; i >= 0; i--){ 
                tbm.removeRow(i); 
            } 
            int i = 0; 
        }
    }//GEN-LAST:event_cmbCursoActionPerformed

    private void tblTurDisMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblTurDisMouseClicked
        carregarAlunoDisciplina();
    }//GEN-LAST:event_tblTurDisMouseClicked

    private void btnAdicionarAlunoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarAlunoActionPerformed
        //verificar o combobox turma
        if(cmbTurma.getSelectedIndex() == -1 ){
            JOptionPane.showMessageDialog(null,"Turma inválida", 
                    "Selecione a turma", JOptionPane.INFORMATION_MESSAGE);
        }else{
            //verificar se a disciplina foi selecionada
            if(tblTurDis.getSelectedRow() == -1){
                JOptionPane.showMessageDialog(null,"Selecione uma disciplina", 
                    "Selecione a disciplina", JOptionPane.INFORMATION_MESSAGE);    
            }else{
                //verificar se o aluno foi selecionado
                if(tblAluno.getSelectedRow() == -1){
                    JOptionPane.showMessageDialog(null,"Selecione um aluno para "
                            + " adicionara ve", 
                        "Selecione o aluno", JOptionPane.INFORMATION_MESSAGE);    
                }else{
                    // Seta nome da turma, da disciplina, do aluno e ra.
                    tabd.setNomeTurma(cmbTurma.getSelectedItem().toString());
                    tabd.setNomeDisciplina((String)tblTurDis.getValueAt(tblTurDis.getSelectedRow(), 1));
                    tabd.setRaAluno((Integer)tblAluno.getValueAt(tblAluno.getSelectedRow(), 0));
                    tabd.setNomeAluno((String)tblAluno.getValueAt(tblAluno.getSelectedRow(), 1));
                    tabd.setNota(0);
                    tabd.setFreq(0);
                    tabd.setAprovado(false);
                    tabd.setCreditosDisciplina(tabdDao.capturarCreditosDisciplina((String)tblTurDis.getValueAt(tblTurDis.getSelectedRow(), 1)));
                    if(tabdDao.inserirAluno(tabd)){
                        carregarAlunoDisciplina();
                    }
                }    
            }
        }        
    }//GEN-LAST:event_btnAdicionarAlunoActionPerformed

    private void btnRemoverAlunoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverAlunoActionPerformed
        if(tblAluDis.getSelectedRow() == -1){ // Não selecionou nenhuma Linha
            JOptionPane.showMessageDialog(null,"Selecione um aluno para excluir",
                    "Selecione o aluno", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            Object[] opcoes = { "Sim", "Não" };
             //Obtem os dados de acordo com a linha ao qual foi selecionada.
            Integer linha = tblAluDis.getSelectedRow();
            Integer resposta =JOptionPane.showOptionDialog(null,
                    "Deseja excluir este aluno ?", "Exclusão",JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null,
                    opcoes, opcoes[1]);
            
            // Verifica Resposta do Usuário
            if(resposta == JOptionPane.OK_OPTION){
                
                // Seta nome da turma, da disciplina, do aluno e ra.
                tabd.setNomeTurma(cmbTurma.getSelectedItem().toString());
                tabd.setNomeDisciplina((String)tblTurDis.getValueAt(tblTurDis.getSelectedRow(), 1));
                tabd.setRaAluno((Integer)tblAluDis.getValueAt(tblAluDis.getSelectedRow(), 0));
                tabd.setNomeAluno((String)tblAluDis.getValueAt(tblAluDis.getSelectedRow(), 1));
                //excluir
                
                if(tabdDao.excluirAluno(tabd)){
                    JOptionPane.showMessageDialog(null,"Exclusão realizada com sucesso", 
                        "Excluir", JOptionPane.INFORMATION_MESSAGE);   
                    //recarregar o jTable
                    carregarAlunoDisciplina();
                }
                else{
                    JOptionPane.showMessageDialog(null,"Nao foi possível realizar a exclusão", 
                        "Excluir", JOptionPane.INFORMATION_MESSAGE);
                }
            }
            else{
                JOptionPane.showMessageDialog(null,"Exclusão cancelada", "Exclusão", JOptionPane.INFORMATION_MESSAGE);
            }
        }        
    }//GEN-LAST:event_btnRemoverAlunoActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        if(tblTurDis.getSelectedRow() == -1){ // Não selecionou nenhuma Linha
            JOptionPane.showMessageDialog(null,"Selecione uma disciplina para excluir",
                    "Selecione a disciplina", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            Object[] opcoes = { "Sim", "Não" };
             //Obtem os dados de acordo com a linha ao qual foi selecionada.
            Integer linha = tblTurDis.getSelectedRow();
            Integer resposta =JOptionPane.showOptionDialog(null,
                    "Deseja excluir esta disciplina ?", "Exclusão",JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null,
                    opcoes, opcoes[1]);
            
            // Verifica Resposta do Usuário
            if(resposta == JOptionPane.OK_OPTION){
                
                // Seta nome da turma, da disciplina, do aluno e ra.
                tdbd.setNomeTurma(cmbTurma.getSelectedItem().toString());
                tdbd.setNomeDisciplina((String)tblTurDis.getValueAt(tblTurDis.getSelectedRow(), 1));

                //excluir
                
                if(tdbdDao.excluirDisciplina(tdbd)){
                    JOptionPane.showMessageDialog(null,"Exclusão realizada com sucesso", 
                        "Excluir", JOptionPane.INFORMATION_MESSAGE);   
                    //recarregar o jTable
                    carregarTabela();
                }
                else{
                    JOptionPane.showMessageDialog(null,"Nao foi possível realizar a exclusão", 
                        "Excluir", JOptionPane.INFORMATION_MESSAGE);
                }
            }
            else{
                JOptionPane.showMessageDialog(null,"Exclusão cancelada", 
                        "Exclusão", JOptionPane.INFORMATION_MESSAGE);
            }
        }       
    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
        if(tblTurDis.getSelectedRow() == -1){ // Não selecionou nenhuma Linha
            JOptionPane.showMessageDialog(null,"Selecione uma disciplina para alterar", 
                    "Selecione a disciplina", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {          
            //Obtem os dados de acordo com a linha ao qual foi selecionada.
            Integer linha = tblTurDis.getSelectedRow();

            tdbd.setNomeTurma((String)cmbTurma.getSelectedItem().toString());
            tdbd.setSemestre((Integer)tblTurDis.getValueAt(linha, 0));
            tdbd.setNomeDisciplina((String)tblTurDis.getValueAt(linha, 1));
            tdbd.setNomeProfessor((String)tblTurDis.getValueAt(linha, 2));
            tdbd.setCodDisciplina((Integer)tblTurDis.getValueAt(linha, 3));
            tdbd.setCodProfessor((Integer)tblTurDis.getValueAt(linha, 4));
            //Manda os dados para a tela de Alterar
            this.enable();
            TelaAltTurmaDisciplina altdis = new TelaAltTurmaDisciplina(null, true);
            altdis.carregarComboDisciplina();
            altdis.carregarComboProfessor();
            altdis.carregarComboTurma(jycAno.getValue());
            altdis.recebeObjejo(tdbd);
            altdis.setVisible(true);
            //Recarregar a tabela
            carregarTabela();
        }         
    }//GEN-LAST:event_btnAlterarActionPerformed

    //evento de setas da tableTurDis..Carregar alunos
    private void tblTurDisKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tblTurDisKeyReleased
        if(evt.getKeyCode() == KeyEvent.VK_DOWN || evt.getKeyCode() == KeyEvent.VK_UP)
        {
            //carregar alunos cadastrados na disciplina
            carregarAlunoDisciplina();
        }
    }//GEN-LAST:event_tblTurDisKeyReleased

    private void btnTelaAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTelaAreaActionPerformed
        this.setEnabled(false); //trava tela
        TelaArea telarea = new TelaArea(null, true);
        telarea.carregarTabela(); // carrega tabela da tela area
        telarea.setVisible(true); // abre tela area
        cmbArea.removeAllItems(); //limpa combo de área
        carregarComboArea(); //recarrega combo area
        this.setEnabled(true); //destrava tela
    }//GEN-LAST:event_btnTelaAreaActionPerformed

    private void cmbAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAreaActionPerformed
        if(cmbArea.getSelectedIndex() == -1 || cmbArea.getSelectedIndex() == 0){ // tratamento de erro se combo estiver vazio
            cmbDisciplina.removeAllItems();
            cmbDisciplina.setEnabled(false);
        }
        else{
            cmbDisciplina.setEnabled(true);
            cmbDisciplina.removeAllItems(); //limpa combobox
            carregarComboDisciplina(cmbArea.getSelectedItem().toString());
        }    
    }//GEN-LAST:event_cmbAreaActionPerformed

    private void jycAnoIngressoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jycAnoIngressoPropertyChange
        if(flagAnoIngresso == 0){
            flagAnoIngresso = 1;
        }else{
            //Carrega alunos cadastrados no curso para aquele ano de ingresso
            if(cmbCurso.getSelectedIndex() != -1){
                carregarAluno();
            }
        }       
    }//GEN-LAST:event_jycAnoIngressoPropertyChange

    private void btnSalvarNotasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarNotasActionPerformed
        
        //verificar o combobox turma
        if(cmbTurma.getSelectedIndex() == -1 ){
            JOptionPane.showMessageDialog(null,"Turma inválida", 
                    "Selecione a turma", JOptionPane.INFORMATION_MESSAGE);
        }else{
            //verificar se a disciplina foi selecionada
            if(tblTurDis.getSelectedRow() == -1){
                JOptionPane.showMessageDialog(null,"Selecione uma disciplina", 
                    "Selecione a disciplina", JOptionPane.INFORMATION_MESSAGE);    
            }else{
                    String turma = cmbTurma.getSelectedItem().toString(); // turma
                    String disciplina = (String) tblTurDis.getValueAt(tblTurDis.getSelectedRow(), 1); // disciplina
                    boolean aviso = false;
                    
                    for(int i = 0; i < tblAluDis.getRowCount(); i++){
                        AlunoDAO aluno = new AlunoDAO();
                        CursoDAO curso = new CursoDAO();
                        MetodosVerificacaoBD mv = new MetodosVerificacaoBD();
                        String nome = (String) tblAluDis.getValueAt(i,1);
                        float nota = (Float)tblAluDis.getValueAt(i, 2); // nota
                        float freq = (Float)tblAluDis.getValueAt(i,3); // freq
                        boolean aprovado = (Boolean)tblAluDis.getValueAt(i,4);
                        int creditosdisciplina = (Integer)tblAluDis.getValueAt(i,5);
                        int ra = (Integer)tblAluDis.getValueAt(i,0); // ra
                        
                        //verificacao dos dados, nota tem que ser entre 0 e 10 e freq entre 0 e 100
                        if(nota > 10 || nota < 0 || freq > 100 || freq < 0 || creditosdisciplina < 0 || creditosdisciplina > 99999){
                            aviso = true;
                            //se entrar aqui, informa que tem coisa errada e precisa arrumar
                        }
                        else{
                            if(!tabdDao.salvarNota(nota,freq, aprovado, creditosdisciplina, ra,turma,disciplina))
                                aviso = false;
                        try {
                            if ((curso.buscarCreditosCurso(String.valueOf(ra)) - mcDAO.creditosTotaisAluno(ra)) <= 0){
                             
                                atDAO.verificaExclusaoAtividade(String.valueOf(ra),"Creditos faltantes");
                            }
                            else{                              
                                 atDAO.verificaExclusaoAtividade(String.valueOf(ra),"Creditos faltantes");
                                try {
                                    
                                    atDAO.inserirAlerta(nome, mv.stringToDate(mv.convDataBra(aluno.dataIngressoAluno(ra))), String.valueOf(ra), "Creditos faltantes", 3);
                                } catch (ParseException ex) {
                                    Logger.getLogger(TelaTurmaDisciplina.class.getName()).log(Level.SEVERE, null, ex);
                                }

                                
                            }
                                
                                
                        
                            
                            //se nao tiver coisa errada, ele salva.
                            //teoricamente, ele não salva o que estiver errado mas salva o tiver certo
                        } catch (SQLException ex) {
                            Logger.getLogger(TelaTurmaDisciplina.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        }
                    }

                    if(aviso){
                        JOptionPane.showMessageDialog(null,"Alguns dados não puderam ser incluídos pois existem inconsistências"
                                + "\nem notas ou frequência. Verifique e salve novamente.", 
                                    "Inconsistência de dados", JOptionPane.INFORMATION_MESSAGE);
                    }
                    else{
                        JOptionPane.showMessageDialog(null,"Notas salvas com sucesso", 
                                    "Salvar notas", JOptionPane.INFORMATION_MESSAGE);
                    }

                    carregarAlunoDisciplina(); 
                
            }
        }
    }//GEN-LAST:event_btnSalvarNotasActionPerformed

    private void btnRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRelatorioActionPerformed
        int linha = tblTurDis.getSelectedRow();
        if(cmbTurma.getSelectedIndex() == -1 ){
            JOptionPane.showMessageDialog(null,"Turma inválida", 
                    "Selecione a turma", JOptionPane.INFORMATION_MESSAGE);
        }else{
            //verificar se a disciplina foi selecionada
            if(linha == -1){
                JOptionPane.showMessageDialog(null,"Selecione uma disciplina", 
                    "Selecione a disciplina", JOptionPane.INFORMATION_MESSAGE);    
            }else{
        
                ArrayList<TurmaAlunoDisciplinaBD> listaTurma = new ArrayList();
                listaTurma = (ArrayList<TurmaAlunoDisciplinaBD>) carregarAlunoDisciplina();
                Relatorios relatorio = new Relatorios();

                String turma = cmbTurma.getSelectedItem().toString();
                String disciplina = (String)tblTurDis.getValueAt(linha, 1);
                String nomeProfessor = (String)tblTurDis.getValueAt(linha, 2);
                String nomeSheet = (String)tblTurDis.getValueAt(linha, 1) + "_" + nomeProfessor;
                
                relatorio.relatorioDeNotas(nomeSheet, listaTurma, turma, disciplina, nomeProfessor );
            }
        }
       
    }//GEN-LAST:event_btnRelatorioActionPerformed

    //Carregar Curso
    public void carregarComboCurso(){ //de acordo com o ano
        cmbCurso.removeAllItems();//limpar combo
        listacurso.removeAll(listacurso); //limpar a lista
        listacurso = curDao.carregarComboCurso();
        
        for(int i = 0; i<listacurso.size(); i++){
            cmbCurso.addItem(listacurso.get(i).getNome());
        } 
    }
    
    //Carregar Turma
    public void carregarComboTurma(int ano){ //de acordo com o ano        
        cmbTurma.removeAllItems();//limpar combo
        listaturma.removeAll(listaturma); //limpar a lista
        listaturma = turDao.carregarComboAno(ano);
        
        for(int i = 0; i<listaturma.size(); i++){
            cmbTurma.addItem(listaturma.get(i).getNome());
        } 
    }
    
    //Carregar Disciplinas
    public void carregarComboDisciplina(String nomeArea){
        cmbDisciplina.removeAllItems();//limpar combo
        listadisciplina.removeAll(listadisciplina); //limpar a lista
        listadisciplina = disDao.carregarComboPorArea(nomeArea);
        
        for(int i = 0; i<listadisciplina.size(); i++){
            cmbDisciplina.addItem(listadisciplina.get(i).getNome());
        } 
    }
    
    //Carregar os professores
    public void carregarComboProfessor(){
        cmbProfessor.removeAllItems();//limpar combo
        listaprofessor.removeAll(listaprofessor); //limpar a lista
        listaprofessor = proDao.carregarComboProfessor();
        
        for(int i = 0; i<listaprofessor.size(); i++){
            cmbProfessor.addItem(listaprofessor.get(i));
        } 
    }
    
     //Carregar as areas
    public void carregarComboArea(){
        cmbArea.removeAllItems();//limpar combo
        listaarea.removeAll(listaarea); //limpar a lista
        listaarea = areDao.carregarComboArea();
        
        for(int i = 0; i<listaarea.size(); i++){
            cmbArea.addItem(listaarea.get(i).getNome());
        } 
    }
    
    public void carregarTabela(){
        List<TurmaDisciplinaBD> listatd = new ArrayList<TurmaDisciplinaBD>(); 
        
        // Carrega as disciplinas cadastradas para turma selecionada
        listatd = tdbdDao.filtro("t.nome_turma", cmbTurma.getSelectedItem().toString());
        
        //define um modelo para a Jtable
        DefaultTableModel tbm = (DefaultTableModel)tblTurDis.getModel();         
        
        //Remove as linhas da Jtable, para limpar.
        for(int i = tbm.getRowCount()-1; i >= 0; i--){ 
            tbm.removeRow(i); 
        } 
        int i = 0; 
        
        //Para cada disciplina que ele encontrar, adiciona uma nova linha na Jtable
        for(TurmaDisciplinaBD td : listatd){            
            tbm.addRow(new String[1]); 
            tblTurDis.setValueAt(td.getSemestre(), i, 0);
            tblTurDis.setValueAt(td.getNomeDisciplina(), i, 1); 
            tblTurDis.setValueAt(td.getNomeProfessor(), i, 2);
            tblTurDis.setValueAt(td.getCodDisciplina(), i, 3);     
            tblTurDis.setValueAt(td.getCodProfessor(), i, 4);     
            i++; 
        }
        centralizarTable();
    }

    public void carregarAluno(){
        List<AlunoBD> listaal = new ArrayList<AlunoBD>(); 

        //Carrega os alunos cadastrados no curso
        listaal = tabdDao.filtroAluno(cmbCurso.getSelectedItem().toString(), String.valueOf(jycAnoIngresso.getValue()));
        
        //define um modelo para a Jtable
        DefaultTableModel tbm = (DefaultTableModel)tblAluno.getModel();         
        
        //Remove as linhas da Jtable, para limpar.
        for(int i = tbm.getRowCount()-1; i >= 0; i--){ 
            tbm.removeRow(i); 
        } 
        int i = 0; 
        
        //Para cada aluno que ele encontrar, adiciona uma nova linha na Jtable
        for(AlunoBD al : listaal){            
            tbm.addRow(new String[1]); 
            tblAluno.setValueAt(al.getRa(), i, 0);
            tblAluno.setValueAt(al.getNome(), i, 1);          
            i++; 
        }
        centralizarTable();
    }    

    public List carregarAlunoDisciplina(){
        List<TurmaAlunoDisciplinaBD> listaAlDis = new ArrayList(); 
        
        Integer linha = tblTurDis.getSelectedRow();         
        if(linha != -1){
            //Carrega os alunos cadastrados no curso
            listaAlDis = tabdDao.filtroAlunoDis("d.nome_dis", 
                    (String)tblTurDis.getValueAt(linha, 1), cmbTurma.getSelectedItem().toString());
              
            //define um modelo para a Jtable
            DefaultTableModel tbm = (DefaultTableModel)tblAluDis.getModel();         

            //Remove as linhas da Jtable, para limpar.
            for(int i = tbm.getRowCount()-1; i >= 0; i--){ 
                tbm.removeRow(i); 
            } 
            int i = 0; 

            //Para cada aluno que ele encontrar, adiciona uma nova linha na Jtable
            for(TurmaAlunoDisciplinaBD tadb : listaAlDis){ 
                tbm.addRow(new String[1]); 
                tblAluDis.setValueAt(tadb.getRaAluno(), i, 0);
                tblAluDis.setValueAt(tadb.getNomeAluno(), i, 1);  
                tblAluDis.setValueAt(tadb.getNota(),i,2);
                tblAluDis.setValueAt(tadb.getFreq(),i,3);
                tblAluDis.setValueAt(tadb.isAprovado(),i,4);
                tblAluDis.setValueAt(tadb.getCreditosDisciplina(),i,5);
                i++; 
            }
            centralizarTable();            
        }
        else{
            limparTableAlunoDisciplina();
        }
        return listaAlDis;

    }
    
    public void limparTableAlunoDisciplina(){
        DefaultTableModel tbm = (DefaultTableModel)tblAluDis.getModel();         

        //Remove as linhas da Jtable, para limpar.
        for(int i = tbm.getRowCount()-1; i >= 0; i--){ 
            tbm.removeRow(i); 
        } 
        int i = 0;        
    }
    
    public void limparTableDisciplinas(){
        DefaultTableModel tbm = (DefaultTableModel)tblTurDis.getModel();         

        //Remove as linhas da Jtable, para limpar.
        for(int i = tbm.getRowCount()-1; i >= 0; i--){ 
            tbm.removeRow(i); 
        } 
        int i = 0;
    }
 
    public void centralizarTable(){
        //Centralizar os dados na tabela.
        DefaultTableCellRenderer center = new DefaultTableCellRenderer();
        center.setHorizontalAlignment(SwingConstants.CENTER ); 
        tblTurDis.getColumnModel().getColumn(0).setCellRenderer(center);
    }
    
    public static void main(String args[]) {

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaTurmaDisciplina.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaTurmaDisciplina.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaTurmaDisciplina.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaTurmaDisciplina.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                TelaTurmaDisciplina dialog = new TelaTurmaDisciplina(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdicionarAluno;
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnAssociar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnRelatorio;
    private javax.swing.JButton btnRemoverAluno;
    private javax.swing.JButton btnSalvarNotas;
    private javax.swing.JButton btnTelaArea;
    private javax.swing.JButton btnVoltar;
    private javax.swing.JComboBox cmbArea;
    private javax.swing.JComboBox cmbCurso;
    private javax.swing.JComboBox cmbDisciplina;
    private javax.swing.JComboBox cmbProfessor;
    private javax.swing.JComboBox cmbSemestre;
    private javax.swing.JComboBox cmbTurma;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private com.toedter.calendar.JYearChooser jycAno;
    private com.toedter.calendar.JYearChooser jycAnoIngresso;
    private javax.swing.JLabel lblArea;
    private javax.swing.JLabel lblCurso;
    private javax.swing.JLabel lblDisciplina;
    private javax.swing.JLabel lblProfessor;
    private javax.swing.JLabel lblSemestre;
    private javax.swing.JPanel pnlAluDis;
    private javax.swing.JPanel pnlAlunoCurso;
    private javax.swing.JPanel pnlAlunoDisciplina;
    private javax.swing.JPanel pnlDisciplina;
    private javax.swing.JPanel pnlPesquisarTurma;
    private javax.swing.JPanel pnlVoltar;
    private javax.swing.JTable tblAluDis;
    private javax.swing.JTable tblAluno;
    private javax.swing.JTable tblTurDis;
    // End of variables declaration//GEN-END:variables
}
